home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1A5RKVD (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  4.3 KB  |  165 lines

  1. package sun.awt.image;
  2.  
  3. import java.awt.image.ColorModel;
  4. import java.awt.image.ImageConsumer;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.util.Hashtable;
  8.  
  9. public abstract class ImageDecoder {
  10.    InputStreamImageSource source;
  11.    InputStream input;
  12.    Thread feeder;
  13.    protected boolean aborted;
  14.    protected boolean finished;
  15.    ImageConsumerQueue queue;
  16.    ImageDecoder next;
  17.  
  18.    public ImageDecoder(InputStreamImageSource src, InputStream is) {
  19.       this.source = src;
  20.       this.input = is;
  21.       this.feeder = Thread.currentThread();
  22.    }
  23.  
  24.    public void abort() {
  25.       this.aborted = true;
  26.       this.source.doneDecoding(this);
  27.       this.close();
  28.       this.feeder.interrupt();
  29.    }
  30.  
  31.    public abstract boolean catchupConsumer(InputStreamImageSource var1, ImageConsumer var2);
  32.  
  33.    public synchronized void close() {
  34.       if (this.input != null) {
  35.          try {
  36.             this.input.close();
  37.          } catch (IOException var1) {
  38.          }
  39.       }
  40.  
  41.    }
  42.  
  43.    protected void headerComplete() {
  44.       this.feeder.setPriority(3);
  45.    }
  46.  
  47.    protected int imageComplete(int status, boolean done) {
  48.       this.source.latchConsumers(this);
  49.       if (done) {
  50.          this.finished = true;
  51.          this.source.doneDecoding(this);
  52.       }
  53.  
  54.       ImageConsumerQueue cq = null;
  55.  
  56.       int count;
  57.       for(count = 0; (cq = this.nextConsumer(cq)) != null; ++count) {
  58.          cq.consumer.imageComplete(status);
  59.       }
  60.  
  61.       return count;
  62.    }
  63.  
  64.    public boolean isConsumer(ImageConsumer ic) {
  65.       return ImageConsumerQueue.isConsumer(this.queue, ic);
  66.    }
  67.  
  68.    protected ImageConsumerQueue nextConsumer(ImageConsumerQueue cq) {
  69.       synchronized(this.source) {
  70.          if (this.aborted) {
  71.             return null;
  72.          }
  73.  
  74.          for(ImageConsumerQueue var4 = cq == null ? this.queue : cq.next; var4 != null; var4 = var4.next) {
  75.             if (var4.interested) {
  76.                return var4;
  77.             }
  78.          }
  79.       }
  80.  
  81.       return null;
  82.    }
  83.  
  84.    public abstract void produceImage() throws IOException, ImageFormatException;
  85.  
  86.    public void removeConsumer(ImageConsumer ic) {
  87.       this.queue = ImageConsumerQueue.removeConsumer(this.queue, ic, false);
  88.       if (!this.finished && this.queue == null) {
  89.          this.abort();
  90.       }
  91.  
  92.    }
  93.  
  94.    public void replayConsumer(ImageConsumer ic) {
  95.    }
  96.  
  97.    protected int setColorModel(ColorModel model) {
  98.       ImageConsumerQueue cq = null;
  99.  
  100.       int count;
  101.       for(count = 0; (cq = this.nextConsumer(cq)) != null; ++count) {
  102.          cq.consumer.setColorModel(model);
  103.       }
  104.  
  105.       return count;
  106.    }
  107.  
  108.    protected int setDimensions(int w, int h) {
  109.       ImageConsumerQueue cq = null;
  110.  
  111.       int count;
  112.       for(count = 0; (cq = this.nextConsumer(cq)) != null; ++count) {
  113.          cq.consumer.setDimensions(w, h);
  114.       }
  115.  
  116.       return count;
  117.    }
  118.  
  119.    protected int setHints(int hints) {
  120.       ImageConsumerQueue cq = null;
  121.  
  122.       int count;
  123.       for(count = 0; (cq = this.nextConsumer(cq)) != null; ++count) {
  124.          cq.consumer.setHints(hints);
  125.       }
  126.  
  127.       return count;
  128.    }
  129.  
  130.    protected int setPixels(int x, int y, int w, int h, ColorModel model, byte[] pix, int off, int scansize) {
  131.       this.source.latchConsumers(this);
  132.       ImageConsumerQueue cq = null;
  133.  
  134.       int count;
  135.       for(count = 0; (cq = this.nextConsumer(cq)) != null; ++count) {
  136.          cq.consumer.setPixels(x, y, w, h, model, pix, off, scansize);
  137.       }
  138.  
  139.       return count;
  140.    }
  141.  
  142.    protected int setPixels(int x, int y, int w, int h, ColorModel model, int[] pix, int off, int scansize) {
  143.       this.source.latchConsumers(this);
  144.       ImageConsumerQueue cq = null;
  145.  
  146.       int count;
  147.       for(count = 0; (cq = this.nextConsumer(cq)) != null; ++count) {
  148.          cq.consumer.setPixels(x, y, w, h, model, pix, off, scansize);
  149.       }
  150.  
  151.       return count;
  152.    }
  153.  
  154.    protected int setProperties(Hashtable props) {
  155.       ImageConsumerQueue cq = null;
  156.  
  157.       int count;
  158.       for(count = 0; (cq = this.nextConsumer(cq)) != null; ++count) {
  159.          cq.consumer.setProperties(props);
  160.       }
  161.  
  162.       return count;
  163.    }
  164. }
  165.